package com.springIOC.container;

import com.springIOC.container.bean.FlatFacade;
import com.springIOC.container.bean.FlatServiceImpl;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

/**
 * <strong>BeanFactory</strong>通过编发方式进行依赖注入与对象管理
 *
 * @author mike
 * @date 2018/03/04
 */
public class BeanFactory {
    public static void main(String[] args) {
//        DefaultListableBeanFactory beanRegister = new DefaultListableBeanFactory();
//        AbstractBeanDefinition flatFacade = new RootBeanDefinition(FlatFacade.class);
//        AbstractBeanDefinition flatService = new RootBeanDefinition(FlatServiceImpl.class);
//        beanRegister.registerBeanDefinition("flatFacade",flatFacade);
//        beanRegister.registerBeanDefinition("flatService",flatService);
//        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
//        mutablePropertyValues.addPropertyValue(new PropertyValue("flatService",flatService));
//        flatFacade.setPropertyValues(mutablePropertyValues);
//        FlatFacade flatFacade1 = (FlatFacade) beanRegister.getBean("flatFacade");
//        flatFacade1.addFLat();
        new BeanFactory().test();
    }

    public void test(){
        DefaultListableBeanFactory beanRegister = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanRegister);
        reader.loadBeanDefinitions(new ClassPathResource("bean3.xml"));
        FlatFacade flatFacade1 = (FlatFacade) beanRegister.getBean("flatFacade");
        flatFacade1.addFLat();
    }
}
